package cn.mpq.payment.controller;

import cn.mpq.payment.Utils.R;
import cn.mpq.payment.common.Annotation.CountAopAnnotation;
import cn.mpq.payment.common.Annotation.LoginAnnotation;
import cn.mpq.payment.common.Annotation.UserLogin;
import cn.mpq.payment.model.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/mpq/aop")
public class AopTestController {
    @RequestMapping("/testBeforeService")
    public String testBeforeService(String key,String value){

        return "key="+key+"  value="+value;
    }
    @RequestMapping("/testAfterReturning")
    public String testAfterReturning(String key){

        return "key=: "+key;
    }
    @RequestMapping("/testAfterReturning01")
    public Integer testAfterReturning01(Integer key){

        return key;
    }
    @RequestMapping("/testAfterThrowing")
    public String testAfterThrowing(String key){

        throw new NullPointerException();
    }
    @RequestMapping("/testAfter")
    public String testAfter(String key){

        throw new NullPointerException();
    }
    @RequestMapping("/testAfter02")
    public String testAfter02(String key){

        return key;
    }
    @RequestMapping("/testAroundService")
    public String testAroundService(String key){

        return "环绕通知："+key;
    }
    @LoginAnnotation("登陆")
    @CountAopAnnotation(value = "美女")
    @RequestMapping("/test")
    public String testAround(String key){

        return "测试："+key;
    }

    /**
     * 测试登陆拦截自定义注解和自定义参数解析器注解
     * @param user
     * @return
     */
    @RequestMapping("/update")
    @LoginAnnotation
    public R updateCarSource(@UserLogin User user) {
         return R.ok().put("user",user);
    }
}
